package  
{
	import flash.external.ExternalInterface;
	import com.facebook.Facebook;
	import com.facebook.FacebookEvent;
	import com.thomasbrault.display.AbstractMovieClip;

	import flash.events.MouseEvent;
	import flash.text.TextField;

	/**
	 * @author t.brault
	 */
	public class FacebookTest extends AbstractMovieClip 
	{
		
		override protected function _addedToStage (  ) : void
		{
			Facebook.dispatcher.addEventListener(FacebookEvent.API, _api);
			
			(getChildByName('mc_login')).addEventListener(MouseEvent.CLICK, _click);			(getChildByName('mc_init')).addEventListener(MouseEvent.CLICK, _click);			(getChildByName('mc_revoke')).addEventListener(MouseEvent.CLICK, _click);
		}

		private function _api(event : FacebookEvent) : void 
		{
			for ( var i in event.object_return )
			{
				(getChildByName('tf') as TextField).text += i+" => "+event.object_return[i]+"\r";
			}
		}

			
		private function _click ( event : MouseEvent ) : void 
		{
			switch ( (event.currentTarget).name )
			{
				case 'mc_init':
					Facebook.init('e4d206cf19a51833016cd5179e40a6a7');
					
					ExternalInterface.call('FB.flash')
				break;
				case 'mc_login':
					Facebook.api('/f8');
				break;
				case 'mc_revoke':
					Facebook.api({method: 'auth.revokeauthorization'});
				break;
			}
		}
	}
}
